//
//  JFNoteViewController.m
//  JobFree2.0
//
//  Created by xxcao on 2017/5/25.
//  Copyright © 2017年 Dale. All rights reserved.
//

#import "JFNoteViewController.h"
#import "SwipeView.h"
#import "JFNoteViewController+CollectionView.h"

@interface JFNoteViewController ()<SwipeViewDelegate,SwipeViewDataSource>

@end

@implementation JFNoteViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    self.title = @"看板";
    [self configureLeftNavigationBarItemWithImage:@"backToTeamIcon"];
}

- (void)handleLeftBtnAction {
    [self.tabBarController.navigationController popViewControllerAnimated:YES];
}

//MARK: getter
- (NSMutableArray *)dataSources {
    if (!_dataSources) {
        _dataSources = [NSMutableArray array];
        NSData *JSONData = [NSData dataWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"MockDatas" ofType:@"json"]];
        NSArray *dataArray = [NSJSONSerialization JSONObjectWithData:JSONData options:NSJSONReadingAllowFragments error:nil];
        [_dataSources addObjectsFromArray:dataArray];
    }
    return _dataSources;
}

//MARK: Swipe View Datasource & Delegate
- (NSInteger)numberOfItemsInSwipeView:(SwipeView *)swipeView {
    return self.dataSources.count;
}

- (UIView *)swipeView:(SwipeView *)swipeView viewForItemAtIndex:(NSInteger)index reusingView:(UIView *)view {
    UICollectionView *colletionView = nil;
    if (view == nil) {
        view = [[UIView alloc] initWithFrame:swipeView.bounds];
        view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
        colletionView = [self setupCollectonView];
        colletionView.tag = 2017;
        [view addSubview:colletionView];
        [colletionView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.equalTo(view);
            make.left.equalTo(view);
            make.right.equalTo(view);
            make.bottom.equalTo(view);
        }];
    }
    return view;
}

- (void)swipeViewCurrentItemIndexDidChange:(SwipeView *)swipeView {
    UIView *view = (UICollectionView *)self.swipeView.currentItemView;
    UICollectionView *colletionView = (UICollectionView *)[view viewWithTag:2017];
    [colletionView reloadData];
}

@end
